package com.hfzy.ihk.web.linkcall.handlers;

import com.alibaba.fastjson.JSON;
import com.hfzy.ihk.common.core.elasticsearch.ElasticsearchOperation;
import com.hfzy.ihk.common.core.elasticsearch.base.CommonTableOperationHandler;
import com.hfzy.ihk.common.facade.elasticsearch.ElasticsearchTableOperation;
import com.hfzy.ihk.common.util.string.StringUtil;
import com.hfzy.ihk.facade.linkcall.entity.task.CallTaskPhone;
import com.hfzy.ihk.facade.linkcall.enums.LinkCallOperations;
import com.hfzy.ihk.facade.linkcall.enums.LinkCallTables;
import com.hfzy.ihk.web.linkcall.biz.CallTaskBiz;
import com.hfzy.ihk.web.linkcall.biz.CallTaskPhoneBiz;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CallTaskPhoneOperationHandler extends CommonTableOperationHandler {
    private static final Logger logger = LoggerFactory.getLogger(CallTaskPhoneOperationHandler.class);

    @Autowired
    CallTaskPhoneBiz callTaskPhoneBiz;

    public CallTaskPhoneOperationHandler() {
        /**
         * 必须定义该处理器对应的table和操作名
         * */
        this.table = LinkCallTables.CALL_TASK_PHONE;

        this.tableOperation = LinkCallOperations.addCallTaskPhones;
    }

    @Override
    protected void toHandle(ElasticsearchOperation elasticsearchOperation) {
        if(elasticsearchOperation!=null){
            Object data = elasticsearchOperation.getData();
            logger.debug("handle data:{}", JSON.toJSONString(data));
            if(data != null || StringUtil.isNotNull(elasticsearchOperation.getOptMethod()))
                switch (elasticsearchOperation.getOptMethod()){
                    case "addCallTaskPhones":
                        callTaskPhoneBiz.addCallTaskPhones((List<CallTaskPhone>) data);
                        break;
                    default:
                        break;
                }
        }
    }
}
